package com.fqgj.xjd.user.controller;

import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.api.Response;
import com.fqgj.xjd.user.client.UserContactService;
import com.fqgj.xjd.user.client.UserInfoService;
import com.fqgj.xjd.user.client.UserLogService;
import com.fqgj.xjd.user.client.UserService;
import com.fqgj.xjd.user.client.request.Carrier;
import com.fqgj.xjd.user.client.request.CopyUserRequest;
import com.fqgj.xjd.user.client.request.UserPromotion;
import com.fqgj.xjd.user.client.response.CopyUserVO;
import com.fqgj.xjd.user.client.response.UserActionLogResponse;
import com.fqgj.xjd.user.config.ConfigUtil;
import com.fqgj.xjd.user.dao.UserBaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Controller
public class OkController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OkController.class);

    @Autowired
    private UserContactService userContactService;

    @Autowired
    private UserLogService userLogService;

    @Autowired
    UserBaseDao userBaseDao;

    @Autowired
    private UserService userService;
    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private ConfigUtil configUtil;

    @Value("${server.test}")
    private String testName;

    @RequestMapping("/ok")
    @ResponseBody
    public String ok(String userCode) {
        UserPromotion userPromotion = new UserPromotion();
        userPromotion.setUserCode(userCode);
        userPromotion.setActionAccess(1);
        userPromotion.setActionType(0);
        userPromotion.setActionDate(new Date());
        userInfoService.addUserPromotion(userPromotion);
        return "ok";
    }

    @RequestMapping("/logok")
    @ResponseBody
    public String logok() {
        LOGGER.info("LOGGER TEST");
        return "logok," + testName;
    }

    @RequestMapping(value = "/addUserCarrier", method = RequestMethod.POST)
    @ResponseBody
    public String addUserCarrier(@RequestBody Carrier carrier) {
        userContactService.addUserCarrier("2019032999006799000101", carrier);
        return "ok";
    }

    @RequestMapping("/ok1")
    @ResponseBody
    public String ok1() {
        List<String> mobiles = new ArrayList<>();
        mobiles.add("18268125687");
        Response<List<UserActionLogResponse>> listResponse = userLogService.queryByTypeAndValues(1, mobiles);
        return "ok";
    }


    @RequestMapping(value = "/copyUser", method = RequestMethod.POST)
    @ResponseBody
    public String copyUser(@RequestBody CopyUserRequest request) {
        Response<CopyUserVO> response = userService.copyUser(request);
        return JSONObject.toJSONString(response);

    }


}